﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    class FLTCCRDReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        public string LO = "";
        public string LB = "";
        public string FROMDATE = "";
        public string ENDDATE = "";
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public FLTCCRDReport()
            : base()
        {
        }
        public FLTCCRDReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            
            #endregion           						
            
        }
        #region------------------------------Function------------------------

        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["CCRD"];
                //exAgent.DataTableToExcel(dtSoruce, 2, 1);
                 DataTable dtOutput = new DataTable();
                 //GABLO	GABLB GABBUCHDAT	GABPARTIE	GABLBEHI	GABART	GABVAR	GSHANDLNR	GSGARNBEZ	
                    //GABFARBE	GSCBEZ	TYPE	KG	GABBUCHBEN

                 dtOutput.Columns.Add("GABLO", typeof(System.String));
                 dtOutput.Columns.Add("GABLB", typeof(System.String));
                 dtOutput.Columns.Add("GABBUCHDAT", typeof(System.String));
                 dtOutput.Columns.Add("GABPARTIE", typeof(System.String));
                 dtOutput.Columns.Add("GABLBEHI", typeof(System.String));
                 dtOutput.Columns.Add("GABART", typeof(System.String));
                 dtOutput.Columns.Add("GABVAR", typeof(System.String));
                 dtOutput.Columns.Add("GSHANDLNR", typeof(System.String));
                 dtOutput.Columns.Add("GSGARNBEZ", typeof(System.String));
                 dtOutput.Columns.Add("GABFARBE", typeof(System.String));
                 dtOutput.Columns.Add("GSCBEZ", typeof(System.String));
                 dtOutput.Columns.Add("TYPE", typeof(System.String));
                 dtOutput.Columns.Add("KG", System.Type.GetType("System.Decimal"));
                 dtOutput.Columns.Add("GABBUCHBEN", typeof(System.String));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);

                exAgent.DataTableToExcel(dtOutput, 2, 1);

                int count = dtOutput.Rows.Count;
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 13, count + 1, 13);
                exAgent.SetCellValue(1, 1, "库");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        {
            try
            {
                string filename = "";
                string sheetName = "";
                string Standard = "FLTCCRD";
                strExcelFile = @"FLT\FLTStandard.xls";
                string filePath = @"C:\intex.w\Report\" + strExcelFile;
                exAgent.Open(filePath);
                //exAgent.Company = strCompany;
                exAgent.strExcelFile = strExcelFile;
                string filedate = LO + "-" + LB + "-" + FROMDATE + "-" + ENDDATE;
                filename = @"色卡研发消耗" + filedate + ".xls";
                sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
                exAgent.CreateNewSheet(filename, Standard, sheetName);
                FillInExcelData(columns, dsSource, 2, 1);
                base.WriteExcelReport("OpenExcel");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }        
        #endregion
    }
}